#coding:utf-8
__author__ = 'yasin'

import urllib2
import json

access_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s'
appid = 'wx06a410b9ec504881'
appsecret = '147e614db2811ec8ab9d2a21f8889d26'

#appid = 'wx1ae1f52cbe28104b'
#appsecret = '9822eb5479dc848db4b536d94b73d7dc'
user_url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=%s'
post_url = 'https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=%s'
#
def get_access_token():
    if True:
        resp = urllib2.urlopen(access_url % (appid, appsecret))
        jresp = resp.read()
        a = json.loads(jresp)
        token = a.get('access_token')
        print token
        return token
    token = 'mnsUI9JU8mw1mAWiyKci1SR9Y-Gar81sM3pTaNe8FS8Q91fQNz2wHKqqafyuxGQM'
    return token

def get_user_list(token):
    resp = urllib2.urlopen(user_url % (token, ''))
    print resp.read()

if __name__ == '__main__':
    token = get_access_token()
    get_user_list(token)